package cn.com.dao;

import cn.com.entity.User;
import cn.com.tool.Jdbc;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

/**
 * <p>Project:Academic - UserDao
 *
 * @author 黄俊玮 On Administrator
 * @version 1.0
 * @DataTime 2024/6/14 09:32:01
 * @since 1.8
 */
public class UserDao {
    public User find(int inPhone,String inPwd){
        User user = null;

        Connection connection = null;
        PreparedStatement preparedStatement = null;
        ResultSet resultSet = null;
        try {
            connection = Jdbc.getConnection();
            preparedStatement = connection.prepareStatement("select * from t_user where phone ="+inPhone+" and pwd ='"+inPwd+"';");
            resultSet = preparedStatement.executeQuery();

            while (resultSet.next()){
                user = new User();
                user.setId(resultSet.getInt("id"));
                user.setName(resultSet.getString("name"));
                user.setPhone(resultSet.getInt("phone"));
                user.setPwd(resultSet.getString("pwd"));
                user.setRole( resultSet.getInt("role"));
                user.setClazz(resultSet.getString("clazz"));
                return user;
            }

        } catch (Exception e) {
            e.printStackTrace();
        }finally {
            Jdbc.close(resultSet,preparedStatement,connection);
        }

        return null;
    }
}
